package com.itheima.youdianda.controller;


import com.itheima.youdianda.common.R;
import com.itheima.youdianda.service.IndexService;
import com.itheima.youdianda.service.SysConfigService;
import com.itheima.youdianda.service.YddUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@RestController
@CrossOrigin(origins = "*")
@RequestMapping("/index")
public class IndexController {
    @Autowired
    private IndexService indexService;
    @Autowired YddUserService yddUserService;


    @PostMapping("/login")
    public R login(@RequestBody Map<String, String> map) {
        return indexService.login(map);
    }

    /**
     * 登录页详情
     *
     * @return
     */
    @GetMapping("/getConfig")
    public R getConfig() {
        return indexService.getConfig();
    }

    /**
     * 网页基本信息
     *
     * @return
     */
    @GetMapping("/baseInfo")
    @CrossOrigin
    public R baseInfo() {
        return indexService.baseInfo();
    }

    /**
     * 获取当前登录用户资料
     *
     * @return
     */
    @PostMapping("/profile")
    public R profile() {
        return indexService.profile();
    }

    /**
     * 热门置顶文章数据(首页)
     *
     * @param page
     * @param limit
     * @return
     */
    @GetMapping("new")
    public R frontPage(Integer page, Integer limit) {
        return indexService.frontPage(page, limit);
    }

    /**
     * 文章列表数据
     *
     * @param page
     * @param limit
     * @param cateid
     * @return
     */
    @GetMapping("list")
    public R articleList(Integer page, Integer limit, Integer cateid) {
        return indexService.articleList(page, limit, cateid);
    }

    /**
     * 用户注册
     * @return
     */
    @PostMapping("/reg")
    public R reg(@RequestBody Map<String, String> map){
        return yddUserService.reg(map);
    }


    @GetMapping("/hot")
    public R hot(){
        return indexService.hot();
    }

    //推荐文章
    @GetMapping("/recommend")
    public R recommend(){
        return indexService.recommend();
    }

    @GetMapping("/show")
    public R show(String id){
        return R.success(indexService.show(id));
    }

    @GetMapping("index")
    public R index(){
        return indexService.index();
    }
}
